<?

class Jscore {
    static $names = array();
    
    static function Engage($name, $js, $css = false) {        
        $js_str = "<script type=\"text/javascript\" src=\"$js\"></script>";
        if($css){
            $js_str.= "<link type=\"text/css\" rel=\"stylesheet\" href=\"$css\">";
        }
        Buffer::Add("JSCORE_$name", $js_str);
        self::$names[] = $name;
    }
    
    static function Init() {        
        $str = "";
        foreach(func_get_args() as $name){
            $str .= Buffer::Get("JSCORE_$name");
        }
        print $str;
    }
    
    static function GetEngagedNames(){
        return self::$names;
    }
    
    static function PhpToJs($varname, $data){
        $str = json_encode($data);
        $var = "bridge.$varname = $str;\n";
        Buffer::Add('JS_BRIDGE', $var);
    }
    
    static function GetBridge(){
        print "<script type=\"text/javascript\">\nvar bridge = {};\n".Buffer::Get('JS_BRIDGE')."</script>";
    }
}